#pragma once

#include "SDL.h"

class SDLInput
{
#pragma region Singleton
public:
	static SDLInput* GetInstance()
	{ 
		if(!instance)
		{
			instance = new SDLInput();
		}
		return instance;
	}
	static void Kill()
	{
		delete instance;
		instance = 0;
	}
private:
	static SDLInput* instance;
	SDLInput();
	SDLInput(const SDLInput& e);
	~SDLInput();
	SDLInput& operator=(const SDLInput& e);
#pragma endregion
public:
	void Poll(SDL_Event e);
	bool IsHeld(SDLKey key){ return keys[key]; }
    bool IsDown(SDLKey key)
	{
		bool isPressed = !lastKeys[key] && keys[key];
		if(isPressed)
			lastKeys[key] = keys[key];
		return isPressed;
	}
	bool IsUp(SDLKey key)
	{ 
		bool isReleased = lastKeys[key] && !keys[key];
		if(isReleased)
			lastKeys[key] = keys[key];
		return isReleased;
	}

private:
	bool keys[SDLK_LAST];
	bool lastKeys[SDLK_LAST];
};

